# coding=utf-8

from web.utils import storage

from db import connection

db = connection.hotel

def get_hotels(word, offset, length):
    """
    分页获取所有酒店记录
    """
    where = ''
    if word:
        where = """
                WHERE name LIKE '%""" + word + """%' 
                    OR name_en LIKE '%""" + word + """%'
            """

    sets = db.query('''
            SELECT SQL_CALC_FOUND_ROWS * 
            FROM hotel
            %s
            ORDER BY id ASC
            LIMIT $offset, $length;''' % where
            , vars = locals())
    totals = db.query('SELECT FOUND_ROWS() AS totals;')
    return storage(result = sets, totalrecords = totals[0].totals)
